<template>
  <div class="echarts-page">
    <el-row>
      <el-col :span="12" class="echart-box">
        <ve-line :data="chartData" height="400px" class="echarts-data" />
        <ve-histogram :data="chartData" height="400px" class="echarts-data" />
      </el-col>
      <el-col :span="12" class="echart-box">
        <ve-pie :data="chartData" height="400px" class="echarts-data" />
        <ve-radar :data="chartData_1" height="400px" class="echarts-data" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getChartData } from '@/api/search'
export default {
  name: 'PanelEcharts',
  data() {
    this.chartSettings = {}
    return {
      chartData: {
        columns: ['日期', '新闻数', '轮播图数'],
        rows: []
      },
      chartData_1: {
        columns: ['日期', '新闻数', '轮播图数', '下单率'],
        rows: [
          {
            日期: '2023-03-04',
            新闻数: 133,
            轮播图数: 109,
            下单率: 0.32
          },
          {
            日期: '2023-03-03',
            新闻数: 350,
            轮播图数: 320,
            下单率: 0.32
          },
          {
            日期: '2023-03-02',
            新闻数: 1393,
            轮播图数: 1093,
            下单率: 0.32
          },
          {
            日期: '2023-02-28',
            新闻数: 3530,
            轮播图数: 3230,
            下单率: 0.32
          }
        ]
      }
    }
  },
  mounted() {
    this.getEchartsData()
  },
  methods: {
    async getEchartsData() {
      try {
        const res = await getChartData()
        this.chartData.rows = res.data.map(item => ({
          '日期': item.date,
          '新闻数': item.newsCount,
          '轮播图数': item.bannerCount
        }))
        console.log(this.chartData)
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.echarts-page {
  margin: 0 20px 30px 20px;
  .echart-box {
    border: 1px solid black;
    &:nth-child(2) {
      border-left: none;
    }
  }
  .echarts-data {
    padding: 15px;
    box-sizing: border-box;
    &:nth-child(2) {
      border-top: 1px solid black;
    }
  }
}

</style>
